/*
 * Copyright 2016 Wealth Inc. All rights reserved.
 */
 package com.wealth.merchant.repository;
import iaas.repository.BaseRepository;

import java.util.List;

import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import com.wealth.merchant.entity.Merchant;

/**
 * @author chan
 * @version 1.0
 * @since 1.0
 */
 
@Repository
public interface MerchantDao extends MerchantCustomerDao, BaseRepository<Merchant, Long> ,JpaSpecificationExecutor<Merchant>{

	/** 查询市场 市场+状态 */
	public List<Merchant> findByMarketIdAndStatus(Long marketId,Integer status);
	
	/** 查询市场 通过用户 */
	@Query(value="select * from t_merchant_merchant a , t_merchant_user b where b.merchant_id = a.id and b.user_id = ?",nativeQuery=true)
	public Merchant findMerchantByUserId(Long userid);
	
	/** 查询参与打折的所有商户 */
	@Query(value="SELECT * FROM t_merchant_merchant m INNER JOIN commodity_goods g WHERE  m.id=g.merchant_id And g.status=2  AND g.is_discount=?1 AND m.id>?2 GROUP BY m.name ORDER BY m.id LIMIT 20 ",nativeQuery=true)
	public List<Merchant> getDiscountGoods(Integer isDiscount,Long maxid);

	
	/** 查询参与满减的所有商户 */
	@Query(value="SELECT * FROM t_merchant_merchant m INNER JOIN commodity_goods g WHERE  m.id=g.merchant_id AND g.status=2  AND g.is_fullcut=?1 AND m.id>?2 GROUP BY m.name ORDER BY m.id LIMIT 20",nativeQuery=true)
	public List<Merchant> getFullcutMerchant(Integer isFullcut,Long maxid);

	/**
	 * 限天超商户
	 * @param type 1 = 限时抢购 2=天天特价 3=超值折扣
	 * @return
	 */
	public List<Merchant> findMerchantByType(int type);

}

